package com.itheima.zixi5.duoxiancheng_chuangjian.method3;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建一个Callable接口的实现类对象
        Callable <String> c1 = new Mycallable(100);
        //创建FutureTask对象，构造方法中传递Callable接口实现类对象
        // FutureTask对象才能执行Callable接口实现类对象中的call()方法
        FutureTask<String> ft1 = new FutureTask<String>(c1);
        //创建一个Thread对象，构造方法中传递FutureTask对象
        //FutureTask对象实现了Runnable接口，所以可以作为Thread对象的构造方法参数
        Thread t1 = new Thread(ft1);
        t1.start();
        String result = ft1.get();
        System.out.println(result);

    }
}
